package apa.data.samples;

import java.io.BufferedReader;
import java.io.IOException;

import apa.data.IOUtil;
import apa.data.Cronos;

public class RowCountAPA {
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("Usage: java WordCount inputFile");
			System.exit(0);
		}
		try {
			Cronos t = new Cronos();
			t.start();
			BufferedReader input = IOUtil.getReader(args[0]);
			int nrows = 0, minc = Integer.MAX_VALUE, maxc = Integer.MIN_VALUE;
			String[] tokens;
			while ((tokens = IOUtil.readTokens(input)) != null) {
				++nrows;
				int nc = tokens.length;
				if (nc < minc)
					minc = nc;
				if (nc > maxc)
					maxc = nc;
			}
			input.close();
			t.stop();
			System.out.println("Rows: " + nrows);
			System.out.println("Min columns: " + minc);
			System.out.println("Max columns: " + maxc);
			System.out.println("Elapsed time (s): " + t.elapsed());
		} catch (IOException e) {
			System.out.println(e.toString());
		}
	}
}
